package com.scalar.chiptrack.operations.discrepancyLotsNotifications.actionCommands;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.operations.discrepancyLotsNotifications.dao.DiscrepancyLotsNotificationsDAO;
import com.scalar.chiptrack.users.User;
import com.scalar.chiptrack.utils.ConfigManager;

/**
 * Created by IntelliJ IDEA.
 * User: Murali Krishna Yengala
 * Date: Sep 12, 2005
 * Time: 7:05:03 PM
 */
public class ConfirmDeleteDiscrepancyLotsCommand extends ChipTrackExtendedAction {

    public ActionForward executeRequest( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        HashMap errors              = ( HashMap ) request.getAttribute( ERROR_MESSAGES );
        HashMap info                = ( HashMap ) request.getAttribute( INFO_MESSAGES );
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute( USER_KEY );

        String[] notificationIds = request.getParameterValues( "notificationIds" );
        if( notificationIds != null )
        {
            try
            {
                DiscrepancyLotsNotificationsDAO.updateNotificationsStatus( notificationIds );
                info.put("Discrepancy Lots Deleted successfully", null);
            }
            catch( Exception e)
            {
                errors.put(ERROR_INTERNAL_SERVER_ERROR, e.getMessage());
            }
        }
        return (new ActionForward (ConfigManager.getIndexPageByGroupName (user.getGroupName())));
    }
}
